package com.igeek.controller;

import com.igeek.model.insurance.Insurance;
import com.igeek.result.Result;
import com.igeek.service.IInsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/insurance")
public class InsuranceController {


    @Autowired
    private IInsuranceService iInsuranceService;


    @GetMapping("getAll")
    public Result getAll(){
        List<Insurance> list=iInsuranceService.list();
        return Result.ok(list);
    }


    //获取详情
    @GetMapping("getDetail/{id}")
    public Result getDetail(@PathVariable("id") Integer id){
        Insurance insurance=iInsuranceService.getById(id);
        return Result.ok(insurance);
    }

    //获取赔付金额
    @GetMapping("getMoney/{id}")
    public Result getMoney(@PathVariable("id") Integer id){
        Insurance insurance=iInsuranceService.getMoney(id);
        return Result.ok(insurance);
    }

    //计算利润
    @PostMapping("getProfit/{id}")
    public Result getProfit(@RequestBody Insurance insurance,@PathVariable("id") Integer id){
        Insurance insurance1=iInsuranceService.getIncome(insurance,id);
        return Result.ok(insurance1);
    }

    //导出Excell
    @GetMapping("export")
    public void export(HttpServletResponse response)  {
        iInsuranceService.export(response);

    }





}
